<?php
require_once 'PHPUnit/Framework.php';

require_once dirname(__FILE__).'/../../../core/core.php';
CCore::Using('mime.parameters');

/**
 * Test class for CCoreMimeParameters.
 */
class CCoreMimeParametersTest extends PHPUnit_Framework_TestCase
{
	/**
	 * @var CCoreMimeParameter
	 */
	protected $parameter;
	
	/**
	 * @var CCoreMimeParameters
	 */
	protected $parameters;

	protected function setUp()
	{
		$this->parameter = new CCoreMimeParameter('key', 'value');
		$this->parameters = new CCoreMimeParameters('test/test;testKey="testValue";test2Key="test2Value"');
	}
	
	public function testParameterName()
	{
		$this->assertEquals($this->parameter->Name(), 'key');
	}

	public function testParameterValue()
	{
		$this->assertEquals($this->parameter->Value(), 'value');
	}

	public function testParameterParse()
	{
		$this->parameter->Parse('newKey="new Value"');

		$this->assertEquals($this->parameter->Name(), 'newKey');
		$this->assertEquals($this->parameter->Value(), 'new Value');

		$this->parameter->Parse('myKey:"my Value"', ':');

		$this->assertEquals($this->parameter->Name(), 'myKey');
		$this->assertEquals($this->parameter->Value(), 'my Value');
	}
	
	public function testGetParamValueByName()
	{
		$this->assertEquals($this->parameters->GetParamValueByName('test2Key'), 'test2Value');
		$this->assertEquals($this->parameters->GetParamValueByName('test99Key'), '');
	}

	public function testGetFirstParam()
	{
		$oParam = $this->parameters->GetFirstParam();
		$this->assertEquals($oParam->Name(), 'test/test');
		$this->assertEquals($oParam->Value(), '');
	}

	public function testAdd()
	{
		$this->assertEquals($this->parameters->Count(), 3);
		$this->parameters->Add($this->parameter);
		$this->assertEquals($this->parameters->Count(), 4);
	}
}
